package com.cms.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cms.dao.mapper.DictManagerMapper;
import com.cms.model.TrCatalog;
import com.cms.model.TrDict;
import com.cms.service.DictService;

@Service
public class DictServiceImpl implements DictService {

	@Autowired
	private DictManagerMapper dictMapper;
	
 

	@Override
	public void delDict(TrDict dict) throws Exception {
        dictMapper.delDict(dict);		
	}
 
	@Override
	public TrDict getDictInfo(TrDict dict) {
		return dictMapper.getDictInfo(dict);
	}

	@Override
	public void saveDict(TrDict dict) throws Exception {
           dictMapper.saveDict(dict);		
	}

	@Override
	public void saveDictCatalogs(List<TrCatalog> catalog) throws Exception
	{
		List<TrCatalog> newCatalog = new ArrayList<TrCatalog>();
		for(TrCatalog log:catalog)
		{
			if(log.getId()==0)
			{
				newCatalog.add(log);
				continue;
			}
			this.dictMapper.updateDictCatalog(log);
		}
		if(!newCatalog.isEmpty())
		{
			this.dictMapper.saveDictCatalog(newCatalog);
		}
	}

	@Override
	public void updateDict(TrDict dict) throws Exception {
           dictMapper.updateDict(dict);		
	}
 
	
	 /**
	  * 
	  * @param log
	  * @return
	  */
	 public List<TrCatalog>queryCatalog()
	 {
		 return dictMapper.queryCatalog();
	 }



	@Override
	public void delCatalog(TrCatalog catalog) throws Exception {
        this.dictMapper.delCatalog(catalog);		
	}

}
